using System.Data.Entity;
using FikriKibar.DataAccess.Abstract;
using FikriKibar.DataAccess.Mapping;
using FikriKibar.Entities.Concrete;

namespace FikriKibar.DataAccess.ContextBase
{
    public class FikriKibarDbContext : DbContext, IFikriKibarDbContext
    {

        public IDbSet<Content> Contents { get; set; }
        public IDbSet<ContentCategory> ContentCategories { get; set; }
        public IDbSet<ContentCategoryHistory> ContentCategoryHistories { get; set; }
        public IDbSet<ContentCategoryLanguageLine> ContentCategoryLanguageLines { get; set; }
        public IDbSet<ContentCategoryLanguageLineHistory> ContentCategoryLanguageLineHistories { get; set; }
        public IDbSet<ContentHistory> ContentHistories { get; set; }
        public IDbSet<ContentLanguageLine> ContentLanguageLines { get; set; }
        public IDbSet<ContentLanguageLineHistory> ContentLanguageLineHistories { get; set; }
        public IDbSet<ContentType> ContentTypes { get; set; }
        public IDbSet<ContentTypeHistory> ContentTypeHistories { get; set; }
        public IDbSet<ContentTypeLanguageLine> ContentTypeLanguageLines { get; set; }
        public IDbSet<ContentTypeLanguageLineHistory> ContentTypeLanguageLineHistories { get; set; }
        public IDbSet<File> Files { get; set; }
        public IDbSet<FileHistory> FileHistories { get; set; }
        public IDbSet<Keyword> Keywords { get; set; }
        public IDbSet<KeywordHistory> KeywordHistories { get; set; }
        public IDbSet<KeywordLanguageLine> KeywordLanguageLines { get; set; }
        public IDbSet<KeywordLanguageLineHistory> KeywordLanguageLineHistories { get; set; }
        public IDbSet<Language> Languages { get; set; }
        public IDbSet<LanguageHistory> LanguageHistories { get; set; }
        public IDbSet<Menu> Menus { get; set; }
        public IDbSet<MenuHistory> MenuHistories { get; set; }
        public IDbSet<MenuItem> MenuItems { get; set; }
        public IDbSet<MenuItemHistory> MenuItemHistories { get; set; }
        public IDbSet<MenuItemLanguageLine> MenuItemLanguageLines { get; set; }
        public IDbSet<MenuItemLanguageLineHistory> MenuItemLanguageLineHistories { get; set; }
        public IDbSet<MenuLanguageLine> MenuLanguageLines { get; set; }
        public IDbSet<MenuLanguageLineHistory> MenuLanguageLineHistories { get; set; }
        public IDbSet<Role> Roles { get; set; }
        public IDbSet<RoleHistory> RoleHistories { get; set; }
        public IDbSet<RoleLanguageLine> RoleLanguageLines { get; set; }
        public IDbSet<RoleLanguageLineHistory> RoleLanguageLineHistories { get; set; }
        public IDbSet<Session> Sessions { get; set; }
        public IDbSet<SessionHistory> SessionHistories { get; set; }
        public IDbSet<Setting> Settings { get; set; }
        public IDbSet<SettingHistory> SettingHistories { get; set; }
        public IDbSet<SettingLanguageLine> SettingLanguageLines { get; set; }
        public IDbSet<SettingLanguageLineHistory> SettingLanguageLineHistories { get; set; }
        public IDbSet<User> Users { get; set; }
        public IDbSet<UserGroup> UserGroups { get; set; }
        public IDbSet<UserGroupHistory> UserGroupHistories { get; set; }
        public IDbSet<UserGroupLanguageLine> UserGroupLanguageLines { get; set; }
        public IDbSet<UserGroupLanguageLineHistory> UserGroupLanguageLineHistories { get; set; }
        public IDbSet<UserGroupRoleLine> UserGroupRoleLines { get; set; }
        public IDbSet<UserGroupRoleLineHistory> UserGroupRoleLineHistories { get; set; }
        public IDbSet<UserGroupUserLine> UserGroupUserLines { get; set; }
        public IDbSet<UserGroupUserLineHistory> UserGroupUserLineHistories { get; set; }
        public IDbSet<UserHistory> UserHistories { get; set; }



        static FikriKibarDbContext()
        {
            Database.SetInitializer<FikriKibarDbContext>(null);
        }

        public FikriKibarDbContext()
            : base("Name=FikriKibarDbContext")
        {
        }

        public FikriKibarDbContext(string connectionString) : base(connectionString)
        {
        }

        public FikriKibarDbContext(string connectionString, System.Data.Entity.Infrastructure.DbCompiledModel model) : base(connectionString, model)
        {
        }

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
        }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);

            modelBuilder.Configurations.Add(new ContentMapping());
            modelBuilder.Configurations.Add(new ContentCategoryMapping());
            modelBuilder.Configurations.Add(new ContentCategoryHistoryMapping());
            modelBuilder.Configurations.Add(new ContentCategoryLanguageLineMapping());
            modelBuilder.Configurations.Add(new ContentCategoryLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new ContentHistoryMapping());
            modelBuilder.Configurations.Add(new ContentLanguageLineMapping());
            modelBuilder.Configurations.Add(new ContentLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new ContentTypeMapping());
            modelBuilder.Configurations.Add(new ContentTypeHistoryMapping());
            modelBuilder.Configurations.Add(new ContentTypeLanguageLineMapping());
            modelBuilder.Configurations.Add(new ContentTypeLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new FileMapping());
            modelBuilder.Configurations.Add(new FileHistoryMapping());
            modelBuilder.Configurations.Add(new KeywordMapping());
            modelBuilder.Configurations.Add(new KeywordHistoryMapping());
            modelBuilder.Configurations.Add(new KeywordLanguageLineMapping());
            modelBuilder.Configurations.Add(new KeywordLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new LanguageMapping());
            modelBuilder.Configurations.Add(new LanguageHistoryMapping());
            modelBuilder.Configurations.Add(new MenuMapping());
            modelBuilder.Configurations.Add(new MenuHistoryMapping());
            modelBuilder.Configurations.Add(new MenuItemMapping());
            modelBuilder.Configurations.Add(new MenuItemHistoryMapping());
            modelBuilder.Configurations.Add(new MenuItemLanguageLineMapping());
            modelBuilder.Configurations.Add(new MenuItemLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new MenuLanguageLineMapping());
            modelBuilder.Configurations.Add(new MenuLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new RoleMapping());
            modelBuilder.Configurations.Add(new RoleHistoryMapping());
            modelBuilder.Configurations.Add(new RoleLanguageLineMapping());
            modelBuilder.Configurations.Add(new RoleLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new SessionMapping());
            modelBuilder.Configurations.Add(new SessionHistoryMapping());
            modelBuilder.Configurations.Add(new SettingMapping());
            modelBuilder.Configurations.Add(new SettingHistoryMapping());
            modelBuilder.Configurations.Add(new SettingLanguageLineMapping());
            modelBuilder.Configurations.Add(new SettingLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserMapping());
            modelBuilder.Configurations.Add(new UserGroupMapping());
            modelBuilder.Configurations.Add(new UserGroupHistoryMapping());
            modelBuilder.Configurations.Add(new UserGroupLanguageLineMapping());
            modelBuilder.Configurations.Add(new UserGroupLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserGroupRoleLineMapping());
            modelBuilder.Configurations.Add(new UserGroupRoleLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserGroupUserLineMapping());
            modelBuilder.Configurations.Add(new UserGroupUserLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserHistoryMapping());
            modelBuilder.Entity<User>().Ignore(t => t.ConfirmPassword);
            modelBuilder.Entity<User>().Ignore(t => t.OldPassword);
            modelBuilder.Entity<ContentCategoryLanguageLine>().Ignore(t => t.ParentNames);


        }

        public static DbModelBuilder CreateModel(DbModelBuilder modelBuilder, string schema)
        {
            modelBuilder.Configurations.Add(new ContentMapping(schema));
            modelBuilder.Configurations.Add(new ContentCategoryMapping(schema));
            modelBuilder.Configurations.Add(new ContentCategoryHistoryMapping(schema));
            modelBuilder.Configurations.Add(new ContentCategoryLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new ContentCategoryLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new ContentHistoryMapping(schema));
            modelBuilder.Configurations.Add(new ContentLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new ContentLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new ContentTypeMapping(schema));
            modelBuilder.Configurations.Add(new ContentTypeHistoryMapping(schema));
            modelBuilder.Configurations.Add(new ContentTypeLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new ContentTypeLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new FileMapping());
            modelBuilder.Configurations.Add(new FileHistoryMapping());
            modelBuilder.Configurations.Add(new KeywordMapping());
            modelBuilder.Configurations.Add(new KeywordHistoryMapping());
            modelBuilder.Configurations.Add(new KeywordLanguageLineMapping());
            modelBuilder.Configurations.Add(new KeywordLanguageLineHistoryMapping());
            modelBuilder.Configurations.Add(new LanguageMapping(schema));
            modelBuilder.Configurations.Add(new LanguageHistoryMapping(schema));
            modelBuilder.Configurations.Add(new MenuMapping(schema));
            modelBuilder.Configurations.Add(new MenuHistoryMapping(schema));
            modelBuilder.Configurations.Add(new MenuItemMapping(schema));
            modelBuilder.Configurations.Add(new MenuItemHistoryMapping(schema));
            modelBuilder.Configurations.Add(new MenuItemLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new MenuItemLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new MenuLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new MenuLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new RoleMapping(schema));
            modelBuilder.Configurations.Add(new RoleHistoryMapping(schema));
            modelBuilder.Configurations.Add(new RoleLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new RoleLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new SessionMapping(schema));
            modelBuilder.Configurations.Add(new SessionHistoryMapping(schema));
            modelBuilder.Configurations.Add(new SettingMapping(schema));
            modelBuilder.Configurations.Add(new SettingHistoryMapping(schema));
            modelBuilder.Configurations.Add(new SettingLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new SettingLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new UserMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupHistoryMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupLanguageLineMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupLanguageLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupRoleLineMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupRoleLineHistoryMapping(schema));
            modelBuilder.Configurations.Add(new UserGroupUserLineMapping());
            modelBuilder.Configurations.Add(new UserGroupUserLineHistoryMapping());
            modelBuilder.Configurations.Add(new UserHistoryMapping(schema));
            modelBuilder.Entity<User>().Ignore(t => t.ConfirmPassword);
            modelBuilder.Entity<User>().Ignore(t => t.OldPassword);
            modelBuilder.Entity<ContentCategoryLanguageLine>().Ignore(t => t.ParentNames);
            return modelBuilder;
        }

    }
}
